require "Common/define"
require "Logic/Config"
require "Common/functions"

UICharactorPreview = {};
HelperFunc.SetUIEnv(UICharactorPreview)
local this = UICharactorPreview;

this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;
this.hasInit = false;

this.currentHeroData = nil; --当前英雄信息
this.isShowModel = false;
this.allHero = {};
this.startDragPos = nil;

this.btnPreviewBack = nil; --退出预览模式
this.btnDrag = nil;

this.canvasRect = nil;

this.iconProfession = nil; --职业
this.textTitleName = nil; --称号
this.textHeroName = nil; --名字

-- 左页签
this.btnInfo = nil; --属性
this.btnSkill = nil; --技能
this.btnWeapon = nil; --专武

this.ctrlBottomGroup = nil;
this.btnBack = nil;
this.btnLeftSwitch = nil;
this.btnRightSwitch = nil;
this.btnArchives = nil; --档案

--可隐藏标签页
---@type FairyGUI.Controller
this.ctrlShowBigDraw = nil
this.ctrlBottom = nil-- ctrlExtraShow,ctrlEmercenaryGroup;
this.btnModelSwitch = nil; --立绘/模型切换
this.btnPreview = nil; --预览

this.btnAward = nil
this.gameObjectName = nil
this.idleTimer = nil;
this.typeName = { "New_occupation_3", "New_occupation_5", "New_occupation_6", "New_occupation_2", "New_occupation_4", "New_occupation_1" };

this.btnCombination = nil;

this.itemConfig = nil;
this.curShowSubPanelName = nil
---@type FairyGUI.GList
-- this.starList = nil
-- this.affectList = nil
---@type FairyGUI.GoWrapper[]
this.drawWrapper = nil
---@type GGraph[]
this.graphicList = nil
---@type GameObject[]
this.objModel = {}
this.oldSelect = nil
local ButtonType = {
    Attr = 0,
    --Equip = 1,
    Skill = 1,
    Weapon = 2,
}
local ModelType = {
    Draw = 1, --原画
    hero = 2, --spine动画
}
this.effFire1 = nil;
this.effFire2 = nil;
this.effFire1Obj = nil;
this.effFire2Obj = nil;
this.effDrawWrapper1 = nil;
this.effDrawWrapper2 = nil;

function UICharactorPreview.Init(heroConfigList, modelId, isShowOne)
    --todo 应该小写 暂时先大写

    currentHeroData = nil;
    allHero = heroConfigList;
    this.isShowOne = isShowOne;
    for i = 1, #allHero do
        if allHero[i].partnerModelId == tostring(modelId) then
            currentHeroData = allHero[i];
            break ;
        end
    end
    if currentHeroData == nil then
        currentHeroData = allHero[0];
    end

    if itemConfig == nil then
        itemConfig = G.dataTable["t_item"];
    end

    local name, package = getUIName(PanelResNames.UICharactorPreview);
    panelMgr:ShowUI(name, package, this.onCreate, Config.useLocalUI);
end
---@param obj FairyGUI.GComponent
function UICharactorPreview.onCreate(obj)
    gameObjectName = obj.gameObjectName
    if not hasInit then
        hasInit = true;
        this.effect_shen = obj:GetChild("effect_shen");
        this.effect_mo = obj:GetChild("effect_mo");

        if this.effect_shen then
            this.effect_shen:ResetClipping();
        end
        if this.effect_mo then
            this.effect_mo:ResetClipping();
        end

        ctrlBottom = obj:GetController("cbottom")
        ctrlShowBigDraw = obj:GetController("ShowBigDraw")
        this.isShowOneController = obj:GetController("isShowOne")
        this.raceController = obj:GetController("race")
        graphicList = { obj:GetChild("draw"), obj:GetChild("modelPos") }
        drawWrapper = { GoWrapper.New(), GoWrapper.New() }
        btnPreviewBack = obj:GetChild("PreviewBackBtn")
        btnDrag = obj:GetChild("DragBtn")
        textTitleName = obj:GetChild("titleName")
        textHeroName = obj:GetChild("name")
        iconProfession = obj:GetChild("profession")

        -- starList = obj:GetChild("StarPanel");
        -- affectList = obj:GetChild("AffectGrid");
        btnInfo = obj:GetChild("attributeBtn")
        btnSkill = obj:GetChild("skillBtn")
        btnWeapon = obj:GetChild("WeaponBtn")

        btnBack = obj:GetChild("backBtn")
        btnLeftSwitch = obj:GetChild("before")
        btnRightSwitch = obj:GetChild("next")
        btnModelSwitch = obj:GetChild("switchBtn")
        btnCombination = obj:GetChild("btnCombination")
        btnPreview = obj:GetChild("previewBtn")
        btnArchives = obj:GetChild("archivesBtn")
        btnAward = obj:GetChild("btn_award")
        effFire1 = obj:GetChild("fire1");
        effFire2 = obj:GetChild("fire2");

        this.btn_comment = obj:GetChild("commentBtn")
        this.comment_num_controller = obj:GetController("CommentState")
        this.comment_num_controller:SetSelectedIndex(0)
        this.txt_comment_num = obj:GetChild("CommentNum")

        resMgr:LoadModelPrefab("UIEff/ef_afm19_fire01", function(go)
            if effDrawWrapper1 == nil then
                effDrawWrapper1 = GoWrapper.New();
            end
            if (effFire1Obj ~= nil) then
                destroyImmediate(effFire1Obj);
                effFire1Obj = nil
            end

            effFire1Obj = newObject(go);
            effFire1Obj:SetActive(true)
            effFire1Obj:AddComponent(TCanvas)
            effFire1Obj:AddComponent(TChangeSortingOrder)

            effDrawWrapper1:SetWrapTarget(effFire1Obj, true)
            --Util.Lua_SetLocalPositionXYZ(self.Role.transform,0,0,0)
            --Util.Lua_GetLocalPositionXYZ(aniObj.transform,0,0,0)
            --Util.Lua_SetLocalScaleXYZ(self.Role.transform,240, 240,1)
            effFire1:SetNativeObject(effDrawWrapper1)
        end)

        resMgr:LoadModelPrefab("UIEff/ef_afm19_fire01", function(go)
            if effDrawWrapper2 == nil then
                effDrawWrapper2 = GoWrapper.New();
            end
            if (effFire2Obj ~= nil) then
                destroyImmediate(effFire2Obj);
                effFire2Obj = nil
            end

            effFire2Obj = newObject(go);
            effFire2Obj:SetActive(true)
            effFire2Obj:AddComponent(TCanvas)
            effFire2Obj:AddComponent(TChangeSortingOrder)

            effDrawWrapper2:SetWrapTarget(effFire2Obj, true)
            --Util.Lua_SetLocalPositionXYZ(self.Role.transform,0,0,0)
            --Util.Lua_GetLocalPositionXYZ(aniObj.transform,0,0,0)
            --Util.Lua_SetLocalScaleXYZ(self.Role.transform,240, 240,1)
            effFire2:SetNativeObject(effDrawWrapper2)
        end)

        ctrlShowBigDraw.selectedIndex = 0
        this.addEvent();

    end
    --closeUI(PanelNames.UIHeadMenu)
    btnAward.visible = false;
    ctrlBottom.selectedIndex = 0
    oldSelect = ctrlBottom.selectedIndex
    this.refresh();
    this.onClickAttribute()

    --if currentHeroData ~= nil then
    --    partnerHandler.HttpGetHeroCommentData(currentHeroData.partnerModelId)
    --end
    this.UpdateCommentNum();
end

function UICharactorPreview.addEvent()
    btnAward.onClick:Add(this.onClickReward)
    btnInfo.onClick:Add(this.onClickAttribute)
    btnSkill.onClick:Add(this.onClickSkill)
    btnWeapon.onClick:Add(this.onClickWeapon)
    btnModelSwitch.onClick:Add(this.onClickModelSwitch)
    btnCombination.onClick:Add(this.onClickCombination)
    btnPreview.onClick:Add(this.onClickPreview)
    btnBack.onClick:Add(this.onClickBack)
    btnLeftSwitch.onClick:Add(this.onClickLeftSwitch)
    btnRightSwitch.onClick:Add(this.onClickRightSwitch)
    btnArchives.onClick:Add(this.onClickArchives)
    btnPreviewBack.onClick:Add(this.onClickPreviewBack)
    btnDrag.onTouchBegin:Add(this.OnBeginDrag);
    btnDrag.onTouchEnd:Add(this.OnEndDrag)
    this.btn_comment.onClick:Add(this.onClickHeroComment)
end

function UICharactorPreview.removeEvent()
    btnAward.onClick:Clear()
    btnInfo.onClick:Clear()
    btnSkill.onClick:Clear()
    btnWeapon.onClick:Clear()
    btnModelSwitch.onClick:Clear()
    btnCombination.onClick:Clear()
    btnPreview.onClick:Clear()
    btnBack.onClick:Clear()
    btnLeftSwitch.onClick:Clear()
    btnRightSwitch.onClick:Clear()
    btnArchives.onClick:Clear()
    btnPreviewBack.onClick:Clear()
    btnDrag.onTouchBegin:Clear()
    btnDrag.onTouchEnd:Clear()

    this.btn_comment.onClick:Clear()
end

function UICharactorPreview.onClickHeroComment()
    -- if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroComment ) then 
    showUI(PanelNames.UICharactorInfoArchives, currentHeroData, 2);
    -- end
end

function UICharactorPreview.LocalListenEvent()
    --ListenEvent(Config.EventType.Fresh_Handbook,this.refreshReward);
end

function UICharactorPreview.LocalCloseEvent()
    logicMgr.FuncOpenManager.removeStatusCtr(PanelNames.UICharactorPreview);

    --CloseEvent(Config.EventType.Fresh_Handbook,this.refreshReward);
    --UIRedDots.removeListen(gameObjectName..btnAward.gameObjectName,Config.RedDotsType.HeroHandbookReward);
end

function UICharactorPreview.OnDestroy()
    hasInit = false
    this.removeEvent();
    for key, value in pairs(this.objModel) do
        destroy(value)
    end
    isShowModel = false
    this.objModel = {}
end

function UICharactorPreview.OnEnable()
    this.LocalListenEvent();
end

function UICharactorPreview.OnDisable()
    this.LocalCloseEvent();

    --HelperFunc.UnloadUnusedAssets(EnumConst.ClearType.Prefab)
end

function UICharactorPreview.refresh()
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICharactorPreview, Config.FuncOpenType.HeroWeapon, btnWeapon.name, btnWeapon);

    if currentHeroData == nil then
        logError("英雄信息为空");
        return ;
    end
    if this.isShowOne then
        this.isShowOneController.selectedIndex = 1;
    else
        this.isShowOneController.selectedIndex = 0;
    end
    iconProfession.visible = true
    iconProfession.url = EnumConst.AtlasPath.ICONAtlas .. typeName[currentHeroData["type"]]
    this.raceController.selectedIndex = currentHeroData.faction
    textHeroName.text = currentHeroData.name;
    textTitleName.text = currentHeroData.subName;
    local heroStar = currentHeroData["star"] / 5000;

    -- local childCount = starList.numItems;
    -- for i = 0,childCount-1 do
    --     ---@type FairyGUI.GComponent
    --     local child = starList:GetChildAt(i)
    --     local ctl = child:GetController("cstar")
    --         ctl:SetSelectedIndex(1)
    -- end
    -- local affectDescribesStr = currentHeroData.pos;
    -- if affectDescribesStr and #affectDescribesStr>0 then
    --     local affectDescribes = decodeJsonStrToTabel(affectDescribesStr);
    --     affectList:RemoveChildrenToPool()
    --     for k,v in pairs(affectDescribes) do
    --         local item = affectList:AddItemFromPool();
    --         item:GetChild("Text").text = getLanguage("HeroPos"..v)
    --     end
    -- end
    this.refreshView();
    --this.refreshReward();
    btnPreviewBack.visible = false

end

function UICharactorPreview.refreshView()
    btnPreview.visible = not isShowModel
    graphicList[ModelType.Draw].visible = not isShowModel
    graphicList[ModelType.hero].visible = isShowModel
    if isShowModel then
        local modelName = currentHeroData.model;
        local objHeroModel = objModel[ModelType.hero]
        local path = HeroManager.GetHeroDrawingRolePath(currentHeroData.partnerModelId);
        if objHeroModel == nil or objHeroModel.name ~= modelName then
            resMgr:LoadModelPrefab(path, function(go)
                if objModel[ModelType.hero] ~= nil then
                    destroyImmediate(objModel[ModelType.hero]);
                    objModel[ModelType.hero] = nil
                end
                local model = newObject(go);
                local aniObj = model.transform:Find("Animation").gameObject;
                model:SetActive(true);
                objModel[ModelType.hero] = model
                model:AddComponent(TCanvas)
                model:AddComponent(TChangeSortingOrder)
                drawWrapper[ModelType.hero]:SetWrapTarget(model, false)
                graphicList[ModelType.hero]:SetNativeObject(drawWrapper[ModelType.hero])
                Util.Lua_SetLocalPositionXYZ(model.transform, currentHeroData.location[3], currentHeroData.location[4], 0);
                Util.Lua_SetLocalScaleXYZ(model.transform, currentHeroData.scale[3], currentHeroData.scale[4], 1)
                Util.Lua_SetLocalRotationXYZ(aniObj.transform, 0, 0, 0);

                local resList = {}
                local refResList = UILoading.GetLoadModelResList()

                for i = 1, #refResList do
                    local array = string.split(refResList[i], "#")
                    if #array > 1 then
                        if array[2] == "Model" then
                            table.insert(resList, array[1])
                        end
                    end
                end

                local heroID = logicMgr.HeroManager.GetRoleHeadID()
                local useSkinId = logicMgr.SkinManager.getHeroSkinId(heroID)
                local path = HeroManager.GetHeroDrawingRolePath(heroID, nil, useSkinId);
                table.insert(resList, path)

                Util.UnloadRoleCache(resList, 3)
            end, true)
        end

    else
        local drawName = currentHeroData.draw;
        local objDrawModel = objModel[ModelType.Draw]
        if objDrawModel == nil or objDrawModel.name ~= drawName then
            if idleTimer ~= nil then
                idleTimer:Stop();
            end
            drawWrapper[ModelType.Draw].visible = false
            resMgr:LoadModelPrefab(drawName, function(go)
                if objModel[ModelType.Draw] ~= nil then
                    destroyImmediate(objModel[ModelType.Draw]);
                    objModel[ModelType.Draw] = nil
                end
                local model = newObject(go);
                model.name = drawName;
                model:SetActive(true);
                objModel[ModelType.Draw] = model
                model:AddComponent(TCanvas)
                drawWrapper[ModelType.Draw].visible = true
                drawWrapper[ModelType.Draw]:SetWrapTarget(model, false)
                graphicList[ModelType.Draw]:SetNativeObject(drawWrapper[ModelType.Draw])
                Util.Lua_SetLocalPositionXYZ(model.transform, currentHeroData.location[1], currentHeroData.location[2], 0);
                Util.Lua_SetLocalScaleXYZ(model.transform, currentHeroData.scale[1], currentHeroData.scale[2], 1);
                this.delayIdle()
                --[[local g = model:GetComponent("SkeletonGraphic")
                g.AnimationState:SetAnimation(0,"idle2",false);
                local idleAniTime = g.AnimationState.Data.SkeletonData:FindAnimation("idle2").Duration;
                if idleTimer == nil then
                    idleTimer = Timer.New(this.delayIdle,idleAniTime,1,false);
                else
                    idleTimer:Reset(this.delayIdle,idleAniTime,1,false);
                end
                idleTimer:Start();--]]

                --Util.UnloadLihuiCache(3)
            end, true);
        end

    end
end

function UICharactorPreview.refreshReward()
    local data = logicMgr.HeroManager.getHandbookByModelId(currentHeroData.partnerModelId, true);
    local flag = data ~= nil and not data.isReward;
    btnAward.visible = flag;
    if flag then
        local initData = {};
        logicMgr.HeroManager.copyHeroConfigbyModelId(currentHeroData.partnerModelId, initData);
        local handbookRewards = decodeJsonStrToTabel(G.dataTable["t_global"]["56"].f_string_value);

        local rewardData = nil;

        for i = 1, #handbookRewards do
            if handbookRewards[i][1] == initData.star then
                rewardData = handbookRewards[i];
                break ;
            end
        end

    end
end

function UICharactorPreview.setPreviewMode(isPreviewMode)
    local select = isPreviewMode and 1 or 0
    ctrlShowBigDraw.selectedIndex = select
    btnPreviewBack.visible = isPreviewMode
    btnDrag.visible = not isPreviewMode

    if curShowSubPanelName ~= nil then
        if isPreviewMode then
            closeUI(curShowSubPanelName);
        else
            showUI(curShowSubPanelName, currentHeroData);
        end
    end
end

function UICharactorPreview.onClickAttribute()
    oldSelect = ctrlBottom.selectedIndex
    this.openSubPanel(PanelNames.UICharactorPreviewAttribute, btnInfo)
end

function UICharactorPreview.onClickSkill()
    oldSelect = ctrlBottom.selectedIndex
    this.openSubPanel(PanelNames.UICharactorPreSkillview, btnSkill)
end

function UICharactorPreview.onClickWeapon()

    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroWeapon, true, btnWeapon) then
        this.openSubPanel(PanelNames.UICharactorPreviewWeapon);
        oldSelect = ctrlBottom.selectedIndex
    else
        ctrlBottom.selectedIndex = oldSelect
    end
end

function UICharactorPreview.onClickModelSwitch()
    isShowModel = not isShowModel;
    this.refreshView();
end

function UICharactorPreview.onClickPreview()
    this.setPreviewMode(true);
end

function UICharactorPreview.onClickStatusSwitch()
    log("点击切换动态/静态立绘");
end

function UICharactorPreview.onClickPreviewBack()
    this.setPreviewMode(false);
end

function UICharactorPreview.onClickLeftSwitch()
    local index = 0;
    for i = 1, #allHero do
        if allHero[i]["partnerModelId"] == currentHeroData["partnerModelId"] then
            index = i;
            break ;
        end
    end
    index = index - 1;
    if index < 1 then
        index = #allHero;
    end
    currentHeroData = allHero[index];
    this.refresh();
    this.openSubPanel(curShowSubPanelName)
    --if currentHeroData ~= nil then
    --    partnerHandler.HttpGetHeroCommentData(currentHeroData.partnerModelId)
    --end
end

function UICharactorPreview.onClickRightSwitch()
    local index = 0;
    for i = 1, #allHero do
        if allHero[i]["partnerModelId"] == currentHeroData["partnerModelId"] then
            index = i;
            break ;
        end
    end
    index = index + 1;
    if index > #allHero then
        index = 1;
    end
    currentHeroData = allHero[index];
    this.refresh();
    this.openSubPanel(curShowSubPanelName)
    --if currentHeroData ~= nil then
    --    partnerHandler.HttpGetHeroCommentData(currentHeroData.partnerModelId)
    --end
end

function UICharactorPreview.onClickBack()
    closeUI(PanelNames.UICharactorPreSkillview)
    closeUI(PanelNames.UICharactorPreviewAttribute)
    closeUI(PanelNames.UICharactorPreviewWeapon)
    closeUI(PanelNames.UICharactorAttributeDetails)
    closeUI(PanelNames.UICharactorPreview);
    --showUI(PanelNames.UIHeadMenu)
end

function UICharactorPreview.onClickArchives()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroArchive, true) then
        showUI(PanelNames.UICharactorInfoArchives, currentHeroData);
    end
end

function UICharactorPreview.OnBeginDrag(evt)
    this.startDragPosX = evt.inputEvent.x;
end

function UICharactorPreview.OnEndDrag(evt)
    if evt and this.startDragPosX then
        local endX = evt.inputEvent.x;
        if endX > this.startDragPosX and math.abs(endX - this.startDragPosX) > 100 then
            this.onClickLeftSwitch();
        elseif this.startDragPosX > endX and math.abs(this.startDragPosX - endX) > 100 then
            this.onClickRightSwitch();
        end
    end
end

function UICharactorPreview.onClickReward()
    local data = logicMgr.HeroManager.getHandbookByModelId(currentHeroData.partnerModelId, true);
    if data ~= nil and not data.isReward then
        partnerHandler.sendHandbookReward(currentHeroData.partnerModelId);
    end
end

--- 显示钻石领取
function UICharactorPreview.ShowCollectAward()
    local cfgInfo = HelperFunc.GetGlobalVlue(56)
    local heroCfgInfo = G.dataTable["t_hero"][tostring(currentHeroData["partnerModelId"])]
    local qualityValue = heroCfgInfo["f_HeroInitialStar"]
    for _, v in pairs(cfgInfo) do
        --英雄品质,物品id,物品数量
        local quality = tonumber(v[1])
        local itemTabID = tonumber(v[2])
        local num = tonumber(v[3])
        if qualityValue == quality then
            showUI(PanelNames.UICommonItemGet, itemTabID, num, false)
            break
        end
    end
end

function UICharactorPreview.openSubPanel(panelName, btn)
    --切换左边页签时调用，关闭上一个面板，开启当前面板
    if curShowSubPanelName ~= nil then
        closeUI(curShowSubPanelName);
    end
    curShowSubPanelName = panelName;
    if curShowSubPanelName ~= nil then
        if panelName == PanelNames.UICharactorPreviewWeapon then
            showUI(curShowSubPanelName, this.currentHeroData, UICharactorPreview.clickWeaponSwitch, this.allHero)
        else
            showUI(curShowSubPanelName, currentHeroData)
        end
    end
end

function UICharactorPreview.delayIdle()
    -- 调用loop的idea
    local model = objModel[ModelType.Draw]
    if model ~= nil then
        this.canClickHero = true;
        if model:GetComponent("SkeletonGraphic").AnimationState then
            if model:GetComponent("SkeletonGraphic").AnimationState.Data.SkeletonData:FindAnimation("idle3") ~= nil then
                model:GetComponent("SkeletonGraphic").AnimationState:SetAnimation(0, "idle3", true);
            else
                model:GetComponent("SkeletonGraphic").AnimationState:SetAnimation(0, "idle1", true);
            end
        end
    end
end

function UICharactorPreview.clickWeaponSwitch(isLeft)
    if isLeft then
        UICharactorPreview.onClickLeftSwitch()
    else
        UICharactorPreview.onClickRightSwitch()
    end
end

function UICharactorPreview.AddCommentNum()
    this.comment_count = this.comment_count or 0
    this.comment_count = this.comment_count + 1
    if this.comment_count <= 0 then
        this.comment_num_controller:SetSelectedIndex(0)
    elseif this.comment_count < 99 then
        this.comment_num_controller:SetSelectedIndex(1)
        this.txt_comment_num.text = tostring(this.comment_count)
    else
        this.comment_num_controller:SetSelectedIndex(1)
        this.txt_comment_num.text = "99"
    end
end

function UICharactorPreview.UpdateCommentNum(msg)
    this.comment_num_controller:SetSelectedIndex(1)
    this.txt_comment_num.text = "99"
    --local hero_id = msg.heroModelId or 0
    --local key = logicMgr.HeroManager.GetRoleId() .. "_" .. hero_id .. "_hero_comment"
    --local comment_list = {}
    --local oss_comment_list = partnerHandler.GetHeroCommentDataByHeroId(hero_id)
    --for _, v in pairs(oss_comment_list) do
    --    comment_id = tostring(v.cid)
    --    comment_list[comment_id] = true
    --end
    --
    --local local_comments_str = Util.GetPlayerPrefs(key)
    --local local_comments = nil
    --if local_comments_str and local_comments_str ~= "" then
    --    local_comments = decodeJsonStrToTabel(local_comments_str)
    --end
    --if local_comments then
    --    for k, v in pairs(local_comments) do
    --        local comment_id = tostring(v.comment_id)
    --        if comment_list[comment_id] == nil then
    --            comment_list[comment_id] = true
    --        end
    --    end
    --end
    --this.comment_count = 0
    --for k, v in pairs(comment_list) do
    --    comment_count = comment_count + 1
    --end
    --
    --if this.comment_count <= 0 then
    --    this.comment_num_controller:SetSelectedIndex(0)
    --elseif this.comment_count < 99 then
    --    this.comment_num_controller:SetSelectedIndex(1)
    --    this.txt_comment_num.text = tostring(this.comment_count)
    --else
    --    this.comment_num_controller:SetSelectedIndex(1)
    --    this.txt_comment_num.text = "99"
    --end

end
function UICharactorPreview.onClickCombination()
    local info = HeroManager.getCombinationInfo()
    local showInfo = HeroManager.getCombinationShowInfo()
    local modelId = currentHeroData.partnerModelId;
    local combinationInfo = clone(showInfo[modelId]) or {};
    local combinationList = {}
    local combinationId = clone(combinationInfo.f_CombinationId)
    if combinationInfo and combinationInfo.f_CombinationId == nil then
        combinationInfo.f_CombinationId = {}
    end
    local isOpen = true;
    if combinationInfo == nil or (combinationInfo and table.getn(combinationInfo.f_CombinationId) == 0) then
        isOpen = false;
    end
    if combinationInfo.f_CombinationId2 ~= "" and combinationInfo.f_CombinationId2 ~= nil and table.getn(combinationInfo.f_CombinationId2) > 0 then
        table.insert(combinationId, combinationInfo.f_CombinationId2[1])
        if info[tostring(combinationInfo.f_CombinationId2[1])].f_Block ~= 1 then
            isOpen = true;
        else
            isOpen = false;
        end
    end
    if combinationId == nil then
        combinationId = {};
    end
    for i, v in pairs(combinationId) do
        local param = {}
        param.skillId = v;
        if info[tostring(v)].f_Block ~= 1 and table.getn(info[tostring(v)].f_CombinationHero) > 0 then
            param.decs = info[tostring(v)].f_CombinationSkillDesc;--技能描述
            local heros = clone(combinationInfo.f_CombinationHero[i])
            table.insert(heros, 1, tonumber(modelId))
            param.heroIds = heros;
            param.type = 0; --普通英雄羁绊
            local isAdd = true;
            for i, v in pairs(param.heroIds) do
                if not logicMgr.HeroManager.isOpenHeroAtlas(v) then
                    isAdd = false;
                end
            end
            if isAdd then
                table.insert(combinationList, param);
                isOpen = true;
            end
        elseif info[tostring(v)].f_Block ~= 1 and table.getn(info[tostring(v)].f_CombinationHero) <= 0 then
            param.type = 1; --普通英雄羁绊
            param.decs = info[tostring(v)].f_CombinationSkillDesc;--技能描述
            param.decs2 = info[tostring(v)].f_CombinationDesc;--技能描述
            table.insert(combinationList, param);
            isOpen = true;
        end
    end
    if isOpen then
        showUI(PanelNames.UIHeroCombination, combinationList);
    else
        UISysTips.AddMsg(getLanguage("ErrorCode_230005"));
    end
end

return UICharactorPreview;
